<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
var correlationAccordionInit = true;


function inintCorrelationIssuePage(){
	
	if(_workEffortId!="isNew"){
		$(".correlationBtn").hide();
	}
	
	//$("#correlationAccordion").accordion({selected:-1});
	//$("#correlationAccordion").accordion('getSelected').panel('collapse');
	associatedDocumentsNum();

	$("#correlationAccordion").accordion({selected:-1,onSelect:function(){
		if(correlationAccordionInit){
			$("#correlationIssueSearchTable").datagrid({
				url:_synergyContext+'/basic/correlationListData',
			    queryParams:getCorrelationIssueSearchParams(),//提交参数
			    
			    toolbar:'#correlationIssueSearchToolbar',//表头工具栏
			    pagination:true,//显示分页  
			    pagePosition:'bottom',//分页栏出现位置
			    pageNumber:1,//初始页码
			    pageSize:10,//初始每页显示记录数量
			    fitColumns:true,
			    columns:[[
					{field:'issueId',title:'',checkbox:true},
					{field:'formName',title:'类型',align:'center'},
					{field:'issueName',title:'公文名称',formatter: function(value,row,index){
						return "<a href=\"javascript:javascript:openDonePage('"+row.issueId+"','"+row.formId+"')\" title='"+value+"'>"+value+"</a>";
					}},
					{field:'displayNumber',title:'发文文号',align:'center'},
					{field:'createTime',title:'拟稿时间',align:'center',formatter: function(value,row,index){
						var str="";
						if(value){
							str=dataFormatStr(new Date(value),"yyyy-MM-dd hh:mm:ss").replace(" ","<br/>");
						}
						return str;
					}},
					{field:'completeTime',title:'办结时间',align:'center',formatter: function(value,row,index){
						var str="";
						if(value){
							str=dataFormatStr(new Date(value),"yyyy-MM-dd hh:mm:ss").replace(" ","<br/>");
						}
						return str;
					}},
					{field:'drafter',title:'拟稿人',align:'center'},
					{field:'drafterOrg',title:'拟稿部门',align:'center'}
			    ]]
			});
					
			$('#correlationIssueTable').datagrid({
			    url:'<c:url value="/docDispatch/correlationIssueList" />',
			    queryParams:getCorrelationIssueParams(),//提交参数
			    
			    toolbar:'#correlationIssueToolbar',//表头工具栏
			    pagination:true,//显示分页  
			    pagePosition:'bottom',//分页栏出现位置
			    pageNumber:1,//初始页码
			    pageSize:10,//初始每页显示记录数量
			    columns:[[
					{field:'docReceiveUuid',title:'',checkbox:true},
					{field:'docName',title:'公文名称',formatter: function(value,row,index){
						return "<a href=\"javascript:javascript:openDonePage('"+row.docId+"','"+row.formId+"')\" title='"+value+"'>"+value+"</a>";
					}},
					{field:'formName',title:'类型'},
					{field:'createTime',title:'创建时间',formatter: function(value,row,index){
						var str="";
						if(value){
							str=dataFormatStr(new Date(value),"yyyy-MM-dd");
						}
						return str;
					}},
					{field:'drafter',title:'创建人'},
					{field:'fromTime',title:'关联时间',formatter: function(value,row,index){
						var str="";
						if(value){
							str=dataFormatStr(new Date(value),"yyyy-MM-dd hh:mm:ss");
						}
						return str;
					}}
			    ]]
			});
			correlationAccordionInit = false;
		}
		
	}});
	$.parser.parse("#correlationIssueSearchDiv"); 
	//弹出框设置
	$("#correlationIssueSearchDiv").dialog({
		title:"可关联公文列表",//标题
		width: 980,//宽度
		height:500,
	    closed: true,//初始关闭
	    modal: true
	});
}

function openDonePage(issueId,formId){
	var url=_synergyContext+"/basic/donePage?issueId="+issueId+"&formId="+formId; 
	var winFeatures = "height="+(window.screen.height-80)+"px,width="+(window.screen.width-20)+"px,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no";
	window.open(url,'_blank',winFeatures);
}

function addCorrelationIssue(){
	if(_issueId){
		refreshSearchTable();
		$("#correlationIssueSearchDiv").dialog('open').window('center');
	}else{
		$.messager.alert("提示",'请先保存数据后再执行本操作');
	}
}

function bindCorrelationIssue(){
	var checkValues = getCheckBoxValue("issueId");
	if(checkValues!=""){
		$.blockUI({ 
			message: '<img src="<c:url value="/images/busy.gif"/>" />&nbsp;&nbsp;<span>正在执行操作 请稍候...</span>', 
			css:{color: '#E17009',fontSize:'17px',padding:'10px'},
			baseZ:9999,
			onBlock:function(){
				var url="<c:url value='/docDispatch/correlationIssueAdd'/>";
				
				$.ajax({           
			        type: "POST",                 
			        url: url,                  
			        data: "docId="+_issueId+"&minorIds="+checkValues,        
			        dataType: 'json',      
					async:false,            
			        timeout: 10000,                  
			        error: function() {retVal = "900";},                  
			        success: function(json) {
			        	if(json.state=="200"){
			        		$('#correlationIssueTable').datagrid({queryParams:getCorrelationIssueParams()});
			        		$("#correlationIssueSearchDiv").dialog("close");
			        	}else{
			        		$.messager.alert("提示",'操作失败，保存数据错误');
			        	}
			         }              
				});	
				$.unblockUI();
			}});
	}
}

function delCorrelationIssue(){
	var checkValues = getCheckBoxValue("docReceiveUuid");
	if(checkValues!=""){
		$.blockUI({ 
			message: '<img src="<c:url value="/images/busy.gif"/>" />&nbsp;&nbsp;<span>正在执行操作 请稍候...</span>', 
			css:{color: '#E17009',fontSize:'17px',padding:'10px'},
			baseZ:9999,
			onBlock:function(){
				var url="<c:url value='/docDispatch/correlationIssueDel'/>";
				
				$.ajax({           
			        type: "POST",                 
			        url: url,                  
			        data: "ids="+checkValues,        
			        dataType: 'json',      
					async:false,            
			        timeout: 10000,                  
			        error: function() {retVal = "900";},                  
			        success: function(json) {
			        	if(json.state=="200"){
			        		$('#correlationIssueTable').datagrid({queryParams:getCorrelationIssueParams()});
			        	}else{
			        		$.messager.alert("提示",'操作失败，删除数据错误');
			        	}
			         }              
				});	
				$.unblockUI();
			}});
	}
}

function refreshSearchTable(){
	$("#correlationIssueSearchTable").datagrid({ queryParams:getCorrelationIssueSearchParams()});
}

function getCorrelationIssueSearchParams(){
	var jsonObj=new Object();
	if($("#issueNameSearch").val()!=""){
		jsonObj.issueName=$("#issueNameSearch").val();
	}
	if($("#displayNumberSearch").val()!=""){
		jsonObj.displayNumber=$("#displayNumberSearch").val();
	}
	if($("#completeTimeStartSearch").val()!=""){
		jsonObj.completeTimeStart=$("#completeTimeStartSearch").val()+" 00:00:00";
	}
	if($("#completeTimeEndSearch").val()!=""){
		jsonObj.completeTimeEnd=$("#completeTimeEndSearch").val()+" 23:59:59";
	}
	if($("#createTimeStartSearch").val()!=""){
		jsonObj.createTimeStart=$("#createTimeStartSearch").val()+" 00:00:00";
	}
	if($("#createTimeEndSearch").val()!=""){
		jsonObj.createTimeEnd=$("#createTimeEndSearch").val()+" 23:59:59";
	}
	if($("#draftOrgSearch").val()!=""){
		jsonObj.draftOrg=$("#draftOrgSearch").val();
	}
	if($("#drafterSearch").val()!=""){
		jsonObj.drafter=$("#drafterSearch").val();
	}
	if($("#objectNameSearch").val()!=""){
		jsonObj.objectName=$("#objectNameSearch").val();
	}
	/*if($("#issueStateSearch").val()!=""){
		jsonObj.issueState=$("#issueStateSearch").val();
	}*/
	if(rcvId!=""){
		jsonObj.majorDocId=rcvId;
	}if(_issueId){
		jsonObj.majorDocId=_issueId;
	}
	jsonObj.issueProcessIdPrefix="DOC_";
	//jsonObj.itemType="dispatch";
	return jsonObj;
}

function getCorrelationIssueParams(){
	var jsonObj=new Object();
	if(rcvId!=""){
		jsonObj.docId=rcvId;
	}else if(_issueId){
		jsonObj.docId=_issueId;
	}
	return jsonObj;
}


//关联的公文文件数
function associatedDocumentsNum(){
	
	var url="<c:url value='/docDispatch/associatedDocumentsNum'/>";
	$.ajax({
		type:"POST",
		url:url,
		data:{majorDocId:_issueId},
		dataType:'json',
		async:false,
		success:function(msg){
			if(msg.associatedDocumentsNum > 0){
				//$("#associatedDocumentsNum").html(msg.associatedDocumentsNum);
				var num = msg.associatedDocumentsNum;
				//num.style.color="red";
				var title="关联的公文"+"("+'<span style="color:red;">'+ num +'</span>'+")";
				$("#theTitle").attr("title",title);
			}else{
				//$("#associatedDocumentsNum").html("无");
				var title="关联的公文";
				$("#theTitle").attr("title",title);
			}
		}
	});
}